package com.chenl.provider.feign.dto.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import java.util.Collections;
import java.util.List;

public class Pager<T> implements IPage<T> {
    @JsonProperty(
        index = 10
    )
    @ApiModelProperty(
        position = 10
    )
    private long totalCount;
    @JsonProperty(
        index = 20
    )
    @ApiModelProperty(
        position = 20
    )
    private long pageSize;
    @JsonProperty(
        index = 30
    )
    @ApiModelProperty(
        position = 30
    )
    private long totalPage;
    @JsonProperty(
        index = 40
    )
    @ApiModelProperty(
        position = 40
    )
    private long currentPage;
    @JsonProperty(
        index = 50
    )
    @ApiModelProperty(
        position = 50
    )
    private List<T> list;
    @JsonProperty(
        index = 60
    )
    @ApiModelProperty(
        position = 60
    )
    private List<OrderItem> orderItems;
    @JsonProperty(
        index = 70
    )
    @ApiModelProperty(
        position = 70
    )
    private boolean searchCount;

    public Pager() {
        this.list = Collections.emptyList();
        this.orderItems = Collections.emptyList();
        this.searchCount = true;
    }

    public Pager(List<T> list, long totalCount, long pageSize, long currPage) {
        this.list = Collections.emptyList();
        this.orderItems = Collections.emptyList();
        this.searchCount = true;
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.currentPage = currPage;
        this.totalPage = (long)Math.ceil((double)totalCount / (double)pageSize);
    }

    public Pager(Page<T> page) {
        this.list = Collections.emptyList();
        this.orderItems = Collections.emptyList();
        this.searchCount = true;
        this.list = page.getRecords();
        this.totalCount = page.getTotal();
        this.pageSize = page.getSize();
        this.currentPage = page.getCurrent();
        this.totalPage = page.getPages();
    }

    public Pager(long current, long size) {
        this(current, size, 0L);
    }

    public Pager(long current, long size, Long total) {
        this.list = Collections.emptyList();
        this.orderItems = Collections.emptyList();
        this.searchCount = true;
        if (current > 1L) {
            this.currentPage = current;
        }

        this.pageSize = size;
        this.totalCount = total;
    }

    public boolean isSearchCount() {
        return this.searchCount;
    }

    @JsonIgnore
    public List<T> getRecords() {
        return this.getList();
    }

    @JsonIgnore
    public IPage<T> setRecords(List<T> records) {
        this.list = records;
        return this;
    }

    @JsonIgnore
    public long getTotal() {
        return this.totalCount;
    }

    @JsonIgnore
    public IPage<T> setTotal(long total) {
        this.totalCount = total;
        return this;
    }

    @JsonIgnore
    public long getSize() {
        return this.pageSize;
    }

    @JsonIgnore
    public IPage<T> setSize(long size) {
        this.pageSize = size;
        return this;
    }

    @JsonIgnore
    public long getCurrent() {
        return this.currentPage;
    }

    @JsonIgnore
    public IPage<T> setCurrent(long current) {
        this.currentPage = current;
        return this;
    }

    public List<OrderItem> orders() {
        return this.orderItems;
    }

    @JsonIgnore
    public long getPages() {
        if (this.getSize() == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.getSize();
            if (this.getTotal() % this.getSize() != 0L) {
                ++pages;
            }

            return pages;
        }
    }

    @JsonIgnore
    public IPage<T> setPages(long pages) {
        return this;
    }

    public long getTotalCount() {
        return this.totalCount;
    }

    public long getPageSize() {
        return this.pageSize;
    }

    public long getTotalPage() {
        return this.totalPage;
    }

    public long getCurrentPage() {
        return this.currentPage;
    }

    public List<T> getList() {
        return this.list;
    }

    public List<OrderItem> getOrderItems() {
        return this.orderItems;
    }

    @JsonProperty(
        index = 10
    )
    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    @JsonProperty(
        index = 20
    )
    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    @JsonProperty(
        index = 30
    )
    public void setTotalPage(long totalPage) {
        this.totalPage = totalPage;
    }

    @JsonProperty(
        index = 40
    )
    public void setCurrentPage(long currentPage) {
        this.currentPage = currentPage;
    }

    @JsonProperty(
        index = 50
    )
    public void setList(List<T> list) {
        this.list = list;
    }

    @JsonProperty(
        index = 60
    )
    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    @JsonProperty(
        index = 70
    )
    public void setSearchCount(boolean searchCount) {
        this.searchCount = searchCount;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Pager)) {
            return false;
        } else {
            Pager<?> other = (Pager)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getTotalCount() != other.getTotalCount()) {
                return false;
            } else if (this.getPageSize() != other.getPageSize()) {
                return false;
            } else if (this.getTotalPage() != other.getTotalPage()) {
                return false;
            } else if (this.getCurrentPage() != other.getCurrentPage()) {
                return false;
            } else {
                Object this$list = this.getList();
                Object other$list = other.getList();
                if (this$list == null) {
                    if (other$list != null) {
                        return false;
                    }
                } else if (!this$list.equals(other$list)) {
                    return false;
                }

                label42: {
                    Object this$orderItems = this.getOrderItems();
                    Object other$orderItems = other.getOrderItems();
                    if (this$orderItems == null) {
                        if (other$orderItems == null) {
                            break label42;
                        }
                    } else if (this$orderItems.equals(other$orderItems)) {
                        break label42;
                    }

                    return false;
                }

                if (this.isSearchCount() != other.isSearchCount()) {
                    return false;
                } else {
                    return true;
                }
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Pager;
    }

    public int hashCode() {
        int PRIME = 1;
        int result = 1;
        long $totalCount = this.getTotalCount();
        result = result * 59 + (int)($totalCount >>> 32 ^ $totalCount);
        long $pageSize = this.getPageSize();
        result = result * 59 + (int)($pageSize >>> 32 ^ $pageSize);
        long $totalPage = this.getTotalPage();
        result = result * 59 + (int)($totalPage >>> 32 ^ $totalPage);
        long $currentPage = this.getCurrentPage();
        result = result * 59 + (int)($currentPage >>> 32 ^ $currentPage);
        Object $list = this.getList();
        result = result * 59 + ($list == null ? 43 : $list.hashCode());
        Object $orderItems = this.getOrderItems();
        result = result * 59 + ($orderItems == null ? 43 : $orderItems.hashCode());
        result = result * 59 + (this.isSearchCount() ? 79 : 97);
        return result;
    }

    public String toString() {
        return "Pager(totalCount=" + this.getTotalCount() + ", pageSize=" + this.getPageSize() + ", totalPage=" + this.getTotalPage() + ", currentPage=" + this.getCurrentPage() + ", list=" + this.getList() + ", orderItems=" + this.getOrderItems() + ", searchCount=" + this.isSearchCount() + ")";
    }
}
